package com.yx.sys.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yx.common.vo.Result;
import com.yx.sys.entity.Followed;
import com.yx.sys.service.IFollowedService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/followed")
public class FollowedController {

    @Autowired
    private IFollowedService followedService;

    @GetMapping("/isFollow")
    public Result<Followed> getFollow(Integer followedId, Integer uId){
        QueryWrapper<Followed> wrapper = new QueryWrapper<>();
        wrapper.eq("followedId",followedId).eq("uId",uId);
        Followed followed = followedService.getOne(wrapper);
        return Result.success(followed,"获取关注信息成功");
    }


    @DeleteMapping("/delFollow")
    public Boolean delFollow(Integer fId){
        boolean remove = followedService.cancelFollow(fId);
        System.out.println(remove);
        return remove;
    }

    @GetMapping("/{uId}")
    public Result<List<Followed>> getFollowNum(@PathVariable("uId") Integer uId){
        QueryWrapper<Followed> wrapper = new QueryWrapper<>();
        wrapper.eq("uId",uId);
        List<Followed> list = followedService.list(wrapper);
        System.out.println(list);
        return Result.success(list,"获取用户关注信息成功");
    }
}
